<style src="./index.scss" lang="scss" scoped rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
    export default {
        mixins: [Vue.prototype.$vFN.Mixins.Base,Vue.prototype.$vFN.Mixins.Edit],
        props: {
// 使用者window实例 必定义
            appWindow: {
                type: Object,
                default: null,
            },
        },
        components: {
            EditorTiptap: async () => Vue.extend(await Vue.prototype.$vFN.Components.Base.EditorTiptap()),
            EditorHtmlParse: async () => Vue.extend(await Vue.prototype.$vFN.Components.Base.EditorHtmlParse()),
        },
        data() {
            return {
                // 初始化状态
                initLoad:false,
                // 编辑类型
                editType: "",
                form: {
                    productDetailHtml: "",
                    decorationId: "",
                },
                templateOptions:[],
            };
        },

        methods: {
           
            validate(e){
                return this.mixinEdit_formValidate("editForm")
            },
            getData() {
                let _d = {
                    productDetailHtml: this.form.productDetailHtml,
                    decorationId: this.form.decorationId,
                }
                return _d;
            },
            async install(params_) {
                this.editType = params_.type;


                // 数据源 商品类目
                this.templateOptions = await this.$vFN.Tools.getSelectListSource({
                    url: "store/decoration/usable-decoration",//mall-site-portal/product/listDecoration
                    data:{
                        templateType:6
                    },
                    format: false,
                },this.appWindow);
                // 设置装修模板（默认为第一个）
                // this.form.decorationId = this.templateOptions[0].id

                if (params_.datasource) {
                    this.form.productDetailHtml = params_.datasource.productDetailHtml;
                    this.form.decorationId = params_.datasource.decorationId;
                }
                this.initLoad = true;
                this.returnData();
            },
            async uninstall() {

                this.$refs["editForm"].resetFields();
            },

            returnData(){
                this.$emit('change', {data:this.getData(),load:this.initLoad})
            },
        },
        mounted() {},
        beforeCreate() {},
        watch: {
            "form": {
                handler(newName, oldName) {
                    this.returnData();
                },
                immediate: true,
                deep: true,
            }
        },
    };
</script>